<?php

declare(strict_types=1);
namespace App\Controller\Api;

use Hyperf\HttpServer\Contract\RequestInterface;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\RequestMapping;
use App\Controller\AbstractController;

/**
 * @Controller(prefix="/Rpc")
 * 远程调用服务
 */
class RpcController extends AbstractController
{
    /**
     * 获取全地址库信息
     * @RequestMapping(path="send", methods="get")
     * @return string[]
     */
    public function send( RequestInterface $request) 
    {
        $contents = 'JTdCJTIybWV0aG9kJTIyJTNBJTIyQ29tbW9kaXR5U2VydmljZS5CYmNCZXN0R29vZHNTZXJ2aWNlLmdldERpc3BhdGNoR29vZHNMaXN0JTIyJTJDJTIyYXJnbWVudHMlMjIlM0ElN0IlMjJiaWQlMjIlM0ExNjMlN0QlMkMlMjJyZXF1ZXN0X2lkJTIyJTNBJTIyMTY4OTA0MTExMjE5NTc0NTY4MTY0YWNiOGQ4MmZhOTElMjIlN0Q=';
        $client = new \Swoole\Client(SWOOLE_SOCK_TCP);
        $client->connect('192.168.10.80',9502);
        $client->send($contents.PHP_EOL);
        $ret = $client->recv(1024*16);
        return mb_convert_encoding(rawurldecode(base64_decode($ret)), 'UTF-8', 'GBK');
        return json_decode(rawurldecode(base64_decode($ret)),true);
    }
}
